#! /bin/bash

# bash script to gather information from a host for later debugging
#
#
# Author: Nathan Hubbard
# URL: http://code.google.com/p/n8foo
# -------------------------------------------------------------------------


TIME=`date +%s`
HOSTNAME=`hostname`
DIR="/tmp/gather.${HOSTNAME}.${TIME}"

mkdir $DIR

# process list
echo "processes"
ps auxwwwwwf >> $DIR/ps.txt
# top
top -bn 1 >> $DIR/top.txt 

# network related
# netstat
echo "network"
netstat -antp >> $DIR/netstat.txt
netstat -i >> $DIR/netstat.txt
# ethtool
ifconfig -a | egrep -v "^ |^$" | awk '{print $1}' | grep ^eth | xargs -ifoo ethtool foo >> $DIR/ethtool.txt
# ifconfig
ifconfig >> $DIR/ifconfig.txt
# arp table
arp -a >> $DIR/arp.txt

echo "kernel stuff"
# semaphore count
ipcs -a >> $DIR/ipcs.txt
# slabinfo
cat /proc/slabinfo >> $DIR/proc_slabinfo.txt
#  proc stat
cat /proc/stat >> $DIR/proc_stat.txt
# sysctl
sysctl -a >> $DIR/sysctl.txt
# ulimit
ulimit -a >> $DIR/ulimit.txt

echo "hardware and os info"
# dmesg
dmesg >> $DIR/dmesg.txt
# meminfo
cat /proc/meminfo >> $DIR/top.txt
# issue
cat /etc/issue >> $DIR/issue.txt
# facter (if installed)
facter >> $DIR/facter.txt
# lspci
lspci >> $DIR/lspci.txt
# lsusb
lsusb >> $DIR/lsusb.txt
# filesystem info
df -kh | grep ^/ | awk '{print $1}'  | xargs -ifoo tune2fs -l foo >> $DIR/tune2fs.txt

echo "performance information"
# vmstat
vmstat 1 10 >> $DIR/vmstat.txt &
# iostat
iostat -hx 1 10 >> $DIR/iostat.txt
# sar
sar -A >> $DIR/sar.txt

echo "open files and handles"
# lsof
lsof -s -V -l >> $DIR/lsof.txt
# fuser
fuser -v / >> $DIR/fuser.txt 2>&1

echo "compressing dir"
# compress dir 
tar -zcf ${DIR}.tgz ${DIR}
echo "info directory is ${DIR}.tgz"
